﻿using JetBrains.Annotations;
using MenuService.Enums;
using Microservice.Shared;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace MenuService.Entities
{
    public class AbpMenu : FullAuditedAggregateRoot<Guid>, IMultiTenant
    {
        /// <summary>
        /// 父Id
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 父Ids
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxIDLength)]
        public string? ParentIds { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [NotNull]
        [MaxLength(DatabaseLengthConsts.MaxNameLength)]
        public string Name { get; set; }

        /// <summary>
        /// 编码
        /// </summary>
        [NotNull]
        [MaxLength(DatabaseLengthConsts.MaxCodeLength)]
        public string Code { get; set; }

        /// <summary>
        /// 菜单类型（字典 0目录 1菜单 2按钮）
        /// </summary>
        public MenuType Type { get; set; }

        /// <summary>
        /// 图标
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxCodeLength)]
        public string Icon { get; set; }

        /// <summary>
        /// 路由地址
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxNameLength)]
        public string Router { get; set; }

        /// <summary>
        /// 组件地址
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxNameLength)]
        public string Component { get; set; }

        /// <summary>
        /// 权限标识
        /// </summary>
        [NotNull]
        [MaxLength(DatabaseLengthConsts.MaxNameLength)]
        public string Permission { get; set; }

        /// <summary>
        /// 应用分类（应用编码）
        /// </summary>
        [NotNull]
        [MaxLength(DatabaseLengthConsts.MaxNameLength)]
        public string Application { get; set; }

        /// <summary>
        /// 打开方式（字典 0无 1组件 2内链 3外链）
        /// </summary>
        public MenuOpenType OpenType { get; set; } = MenuOpenType.NONE;

        /// <summary>
        /// 是否可见（Y-是，N-否）
        /// </summary>
        public bool IsVisible { get; set; }

        /// <summary>
        /// 内链地址
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxUrlLength)]
        public string Link { get; set; }

        /// <summary>
        /// 重定向地址
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxUrlLength)]
        public string Redirect { get; set; }

        /// <summary>
        /// 权重（字典 1系统权重 2业务权重）
        /// </summary>
        public MenuWeight Weight { get; set; } = MenuWeight.DEFAULT_WEIGHT;

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [MaxLength(DatabaseLengthConsts.MaxRemarkLength)]
        public string Remark { get; set; }

        /// <summary>
        /// 状态（字典 0正常 1停用 2删除）
        /// </summary>
        public CommonStatus Status { get; set; } = CommonStatus.ENABLE;

        public Guid? TenantId { get; set; }

        private AbpMenu() { }

        internal AbpMenu(Guid id, Guid? parentId, string? parentIds, [NotNull] string name, [NotNull] string code, MenuType type, string icon, string router, string componet, [NotNull] string permission, [NotNull] string application, MenuOpenType openType, bool isVisible, string link, string redirect, MenuWeight menuWeight, int sort, string remark, CommonStatus commonStatus)
        {
            Id = id;
            this.ParentId = parentId;
            this.ParentIds = parentIds;
            this.Name = name;
            this.Code = code;
            this.Type = type;
            this.Icon = icon;
            this.Router = router;
            this.Component = componet;
            this.Permission = permission;
            this.Application = application;
            this.OpenType = openType;
            this.IsVisible = isVisible;
            this.Link = link;
            this.Redirect = redirect;
            this.Weight = menuWeight;
            this.Sort = sort;
            this.Remark = remark;
            this.Status = commonStatus;

        }
    }
}
